package com.cykj.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class LoginInterceptor implements HandlerInterceptor {

@Autowired
RedisTemplate<String,Object> redisTemplate;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println(request.getRequestURI());
//        if (request.getRequestURI().equals("/login")) { // 假设登录请求的URI是/api/login
//            System.out.println("这是登录请求");
//            return true;
//        }
//
//       String token=request.getHeader("X-token");
//        System.out.println("获取到的token是"+token);
//        if(!redisTemplate.hasKey(token)){
//ResponseDTO dto=new ResponseDTO(0,"请先登录",null);
//response.getWriter().write(JSON.toJSONString(dto));
//return false;
//        }
        return true;

    }
}
